package com.example.park2301.message

import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.example.lib_base.entity.MessageBeanItem
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject


@HiltViewModel
class MessageViewModel @Inject constructor(val apiService: ApiService):BaseViewModel(){

    fun getMessage():Flow<PagingData<MessageBeanItem>>{
        return Pager(PagingConfig(pageSize = 10), pagingSourceFactory = {
            MessageDataSource(apiService)
        }).flow.cachedIn(viewModelScope)
    }
}